﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLToolkit.DataAccess;
using Clipping.Utils;
using System.IO;
using BLToolkit.Validation;

namespace Clipping.Utils
{
    [TableName(Name = "UploadHistory")]
    public class UPLOADHISTORY : ModelBase<UPLOADHISTORY>
    {
        class UPLOADHISTORYUpdater : DBPartUpdater<UPLOADHISTORYUpdater>
        {
            static UPLOADHISTORYUpdater()
            {
                Actions[typeof(UPLOADHISTORYUpdater)] = new List<UpdateAction>();

                #region 数据库升级脚本

                Versions[typeof(UPLOADHISTORYUpdater)] = 0;

                #region 创建表 UploadHistory

                AddUpdateAction(typeof(UPLOADHISTORYUpdater), @"CREATE TABLE UploadHistory(
URL VARCHAR2(500) NOT NULL,
ClientID VARCHAR2(100) NOT NULL,
Timestamp datetime
);      
");
                #endregion

                #endregion
            }
        }

        static UPLOADHISTORY()
        {
            string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DB", "history.db");
            var connPool = DBHelper.CreateDBConnectionPool<HistoryDBUpdater>(dbPath, 10);
            DBHelper.UpdateTableSchema<UPLOADHISTORYUpdater>(connPool);
        }
        [Required]
        public string Url { get; set; }
        /// <summary>
        /// 客户ID
        /// </summary>
        [Required]
        public string ClientId { get; set; }

        public DateTime Timestamp { get; set; }
    }
   
    [TableName(Name = "OpenHistory")]
    public class OPENHISTORY : ModelBase<OPENHISTORY>
    {
        class OPENHISOTRYUpdater : DBPartUpdater<OPENHISOTRYUpdater>
        {
            static OPENHISOTRYUpdater()
            {
                Actions[typeof(OPENHISOTRYUpdater)] = new List<UpdateAction>();

                #region 数据库升级脚本

                Versions[typeof(OPENHISOTRYUpdater)] = 0;

                #region 创建表 OpenHistory

                AddUpdateAction(typeof(OPENHISOTRYUpdater), @"CREATE TABLE OpenHistory(
URL VARCHAR2(500) NOT NULL,
Timestamp datetime
);      
");
                #endregion

                #endregion
            }
        }

        static OPENHISTORY()
        {
            string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DB", "history.db");
            var connPool = DBHelper.CreateDBConnectionPool<HistoryDBUpdater>(dbPath, 10);
            DBHelper.UpdateTableSchema<OPENHISOTRYUpdater>(connPool);
        }

        [Required]
        public string Url { get; set; }

        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// 上传历史数据库升级脚本
    /// </summary>
    public class HistoryDBUpdater : DBUpdater
    {
        /// <summary>
        /// 升级脚本初始化
        /// 所有的数据库操作语句都集中在这里，方便数据库自动升级
        /// </summary>
        static HistoryDBUpdater()
        {
            Actions[typeof(HistoryDBUpdater)] = new List<UpdateAction>();

            #region 数据库升级脚本

            Versions[typeof(HistoryDBUpdater)] = 0;

            #endregion
        }
    }
}
